package com.llgz.hotelmanageapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.llgz.hotelmanageapi.common.CommonResult;
import com.llgz.hotelmanageapi.pojo.DO.RoomInfo;
import com.llgz.hotelmanageapi.mapper.RoomInfoMapper;
import com.llgz.hotelmanageapi.pojo.DO.RoomReserveInfo;
import com.llgz.hotelmanageapi.pojo.DTO.RoomInfoDTO;
import com.llgz.hotelmanageapi.service.RoomInfoServer;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 客房信息 服务实现类
 * </p>
 *
 * @author Bernie_fang
 * @since 2021-07-19
 */
@Service
public class RoomInfoServiceImpl extends ServiceImpl<RoomInfoMapper, RoomInfo> implements RoomInfoServer {

    @Autowired
    private RoomInfoMapper roomInfoMapper;

    @Override
    public IPage<RoomInfo> getRoomInfoWithPage(RoomInfoDTO roomInfoDTO) {
        QueryWrapper<RoomInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("room_id");
        //System.out.println("query ==> " + roomInfoDTO);
        queryWrapper.eq(null != roomInfoDTO.getRoomId(),"room_id",roomInfoDTO.getRoomId());
        queryWrapper.eq(null != roomInfoDTO.getRoomType(),"room_type",roomInfoDTO.getRoomType());
        queryWrapper.eq(null != roomInfoDTO.getRoomStatus(),"room_status",roomInfoDTO.getRoomStatus());
        queryWrapper.eq(null != roomInfoDTO.getRoomFloor(),"room_floor",roomInfoDTO.getRoomFloor());
        queryWrapper.eq(null != roomInfoDTO.getStandPrice(),"stand_price",roomInfoDTO.getStandPrice());
        Page<RoomInfo> roomInfoPage = new Page<>(roomInfoDTO.getPageNum(), roomInfoDTO.getPageSize());
        IPage<RoomInfo> page = roomInfoMapper.selectPage(roomInfoPage,queryWrapper);
        return page;
    }

    @Override
    public Boolean updateRoomStatusByRoomId(Integer roomId, Integer status) {
        //      修改房间状态
        UpdateWrapper<RoomInfo> roomInfoUpdateWrapper = new UpdateWrapper<>();
        roomInfoUpdateWrapper.eq("room_id",roomId);
        roomInfoUpdateWrapper.set("room_status", status);
        roomInfoMapper.update(null,roomInfoUpdateWrapper);
        return true;

    }


}
